package com.zmn.oms.zmn.business.impl.open.channel;

import com.alibaba.fastjson.JSON;
import com.zmn.oms.model.entity.dict.ChannelConfig;
import com.zmn.oms.services.interfaces.dict.ChannelConfigService;
import com.zmn.oms.zmn.business.interfaces.open.channel.ChannelConfigBService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2020/10/30 14:34
 */
@Service("channelConfigBService")
public class ChannelConfigBServiceImpl implements ChannelConfigBService {

    @Autowired
    private ChannelConfigService channelConfigService;

    @Override
    public <T> T getConfig(Integer channelId, Class<T> tClass) {

        ChannelConfig channelConfig = channelConfigService.findByChannelId(channelId);
        if (channelConfig == null || StringUtils.isBlank(channelConfig.getContent())) {
            return null;
        }

        return JSON.parseObject(channelConfig.getContent(), tClass);
    }
}
